package com.becca.cake.model.coupon;

import java.io.Serializable;
import java.util.Date;

import com.becca.cake.core.exception.ServiceException;
import com.becca.cake.util.StringUtil;

/**
 * 规则信息表
 * @copyright  尊星(上海)信息科技有限公司
 * @author hejinguo
 * @date 2016年6月30日 下午6:46:08
 */
public class SalesRuleModel implements Serializable {
    /**  */
    private static final long serialVersionUID = 6605271517324930601L;

    private Integer           id;
    /**规则名称*/
    private String            ruleName;
    /**规则描述*/
    private String            ruleDescribe;
    /**规则类型(0:全额抵扣,1:商品折扣 2：有条件满减 3：无门槛使用 4：每满递减 5：每几件第二件折扣 6:赠品)*/
    private Byte              ruleType;
    /**商品折扣*/
    private Float             discountNumber;
    /**最低订单总额*/
    private Double            lowLimitMoney;
    /**优惠金额*/
    private Double            benefitMoney;
    /**每满金额*/
    private Double            eachFullMoney;
    /**每几件从第几件开始折扣*/
    private Integer           eachFewNumber;
    /**赠品商品组ID*/
    private Integer           goodsGiftsGroupId;
    /**优先级(值越大越先)*/
    private Integer           priority;
    /**是否可用(0:可用 1:不可用)*/
    private Byte              isEnable;
    /**创建时间*/
    private Date              createdDate;
    /**创建人*/
    private String            createdName;
    /**修改时间*/
    private Date              updatedDate;
    /**修改人*/
    private String            updatedName;
    /**免单时限制个数*/
    private Integer limitNumber;
    
    /**是否可用 0：可用*/
    public static final Byte BYTE_IS_ENABLE_USER = 0;
    /**是否可用 0：可用*/
    public static final String IS_ENABLE_USE = "0";
    /**是否可用 1：不可用*/
    public static final String IS_ENABLE_NOT_USE = "1";
    /**限制商品个数不能为空*/
    public static final String LIMIT_NUMBER_NULL = "限制商品个数不能为空";
    /**限制商品个数最小值为1*/
    public static final String LIMIT_NUMBER_MIN_VALUE = "限制商品个数最小值为1";
    /**商品折扣不能为空*/
    public static final String DISCOUNT_NUMBER_NULL = "商品折扣不能为空";
    /**最低订单总额不能为空*/
    public static final String LOWLIMIT_MONEY_NULL = "最低订单总额不能为空";
    /**优惠金额不能为空*/
    public static final String BENEFIT_MONEY_NULL = "优惠金额不能为空";
    /**每满金额不能为空*/
    public static final String EACH_FULL_MONEY_NULL = "每满金额额不能为空";
    /**间隔折扣数不能为空*/
    public static final String EACH_FEW_NUMBER_NULL = "间隔折扣数不能为空";
    /**规则名称不能为空*/
    public static final String RULE_NAME_NULL = "规则名称不能为空";
    /**规则类型不能为空*/
    public static final String RULE_TYPE_NULL = "规则类型不能为空";
    /**优先级不能为空*/
    public static final String PROIORTY_NULL = "优先级不能为空";
    /**优惠金额不能大于最低订单总额*/
    public static final String BENEFIT_MAX_LOWLIMIT = "优惠金额不能大于最低订单总额";
    /**优惠金额不能大于每满金额*/
    public static final String BENEFIT_MAX_EACHFULL = "优惠金额不能大于每满金额";
    /**该规则已设为可用*/
    public static final String IS_ENABLE_EXIST = "该规则已设为可用";
    /**该规则已设为不可用*/
    public static final String IS_NOT_ENABLE_EXIST = "该规则已设为不可用";
    /**操作的规则对象为空*/
    public static final String SALES_RULE_NULL = "操作的规则对象为空";
    /**规则ID为空*/
    public static final String SALES_RULE_ID_NULL = "规则ID为空";
    
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getRuleName() {
        return ruleName;
    }

    public void setRuleName(String ruleName) {
        this.ruleName = ruleName;
    }

    public String getRuleDescribe() {
        return ruleDescribe;
    }

    public void setRuleDescribe(String ruleDescribe) {
        this.ruleDescribe = ruleDescribe;
    }

    public Byte getRuleType() {
        return ruleType;
    }

    public void setRuleType(Byte ruleType) {
        this.ruleType = ruleType;
    }

    public Float getDiscountNumber() {
        return discountNumber;
    }

    public void setDiscountNumber(Float discountNumber) {
        this.discountNumber = discountNumber;
    }

    public Double getLowLimitMoney() {
        return lowLimitMoney;
    }

    public void setLowLimitMoney(Double lowLimitMoney) {
        this.lowLimitMoney = lowLimitMoney;
    }

    public Double getBenefitMoney() {
        return benefitMoney;
    }

    public void setBenefitMoney(Double benefitMoney) {
        this.benefitMoney = benefitMoney;
    }

    public Double getEachFullMoney() {
        return eachFullMoney;
    }

    public void setEachFullMoney(Double eachFullMoney) {
        this.eachFullMoney = eachFullMoney;
    }

    public Integer getEachFewNumber() {
        return eachFewNumber;
    }

    public void setEachFewNumber(Integer eachFewNumber) {
        this.eachFewNumber = eachFewNumber;
    }

    public Integer getGoodsGiftsGroupId() {
        return goodsGiftsGroupId;
    }

    public void setGoodsGiftsGroupId(Integer goodsGiftsGroupId) {
        this.goodsGiftsGroupId = goodsGiftsGroupId;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Byte getIsEnable() {
        return isEnable;
    }

    public void setIsEnable(Byte isEnable) {
        this.isEnable = isEnable;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getCreatedName() {
        return createdName;
    }

    public void setCreatedName(String createdName) {
        this.createdName = createdName;
    }

    public Date getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }

    public String getUpdatedName() {
        return updatedName;
    }

    public void setUpdatedName(String updatedName) {
        this.updatedName = updatedName;
    }

    public Integer getLimitNumber() {
        return limitNumber;
    }

    public void setLimitNumber(Integer limitNumber) {
        this.limitNumber = limitNumber;
    }
    
    /**
     * 校验规则ID是否为空
     * @param id
     */
    public static void validSaveSalesRuleIdNull(Integer id){
        if(id == null){
            throw new ServiceException(SalesRuleModel.SALES_RULE_ID_NULL);
        }
    }
    
    /**
     * 校验控件是否为空
     * @param salesRuleModel
     */
    public static void validSaveSalesRule(SalesRuleModel salesRuleModel){
        if(salesRuleModel == null){
            throw new ServiceException(SalesRuleModel.SALES_RULE_NULL);
        }
        if(StringUtil.isEmpty(salesRuleModel.getRuleName())){
            throw new ServiceException(SalesRuleModel.RULE_NAME_NULL);
        }
        if(salesRuleModel.getPriority() == null){
            throw new ServiceException(SalesRuleModel.PROIORTY_NULL);
        }
        if(salesRuleModel.getRuleType() == null){
            throw new ServiceException(SalesRuleModel.RULE_TYPE_NULL);
        }
        if(salesRuleModel.getRuleType() == 0){
            if(salesRuleModel.getLimitNumber() == null){
                throw new ServiceException(SalesRuleModel.LIMIT_NUMBER_NULL);
            }
            if(salesRuleModel.getLimitNumber() == 0){
                throw new ServiceException(SalesRuleModel.LIMIT_NUMBER_MIN_VALUE);
            }
        }
        
        if(salesRuleModel.getRuleType() == 1 && salesRuleModel.getDiscountNumber() == null){
            throw new ServiceException(SalesRuleModel.DISCOUNT_NUMBER_NULL);
        }
        
        if(salesRuleModel.getRuleType() == 2){
            if(salesRuleModel.getLowLimitMoney() == null ){
                throw new ServiceException(SalesRuleModel.LOWLIMIT_MONEY_NULL);
            }
            if(salesRuleModel.getBenefitMoney() == null ){
                throw new ServiceException(SalesRuleModel.BENEFIT_MONEY_NULL);
            }
            if(salesRuleModel.getBenefitMoney() > salesRuleModel.getLowLimitMoney() ){
                throw new ServiceException(SalesRuleModel.BENEFIT_MAX_LOWLIMIT);
            }
            
        }
        if(salesRuleModel.getRuleType() == 3 && salesRuleModel.getBenefitMoney() == null ){
            throw new ServiceException(SalesRuleModel.BENEFIT_MONEY_NULL);
        }
        if(salesRuleModel.getRuleType() == 4 ){
            if(salesRuleModel.getEachFullMoney() == null){
                throw new ServiceException(SalesRuleModel.EACH_FULL_MONEY_NULL);
            }
            if(salesRuleModel.getBenefitMoney() == null ){
                throw new ServiceException(SalesRuleModel.BENEFIT_MONEY_NULL);
            }
            if(salesRuleModel.getBenefitMoney() > salesRuleModel.getEachFullMoney() ){
                throw new ServiceException(SalesRuleModel.BENEFIT_MAX_EACHFULL);
            }
        }
        if(salesRuleModel.getRuleType() == 5 ){
            if(salesRuleModel.getEachFewNumber() == null){
                throw new ServiceException(SalesRuleModel.EACH_FEW_NUMBER_NULL);
            }
            if(salesRuleModel.getDiscountNumber() == null ){
                throw new ServiceException(SalesRuleModel.DISCOUNT_NUMBER_NULL);
            }
        }
    }

    @Override
    public String toString() {
        return "SalesRuleModel [id=" + id + ", ruleName=" + ruleName + ", ruleDescribe="
               + ruleDescribe + ", ruleType=" + ruleType + ", discountNumber=" + discountNumber
               + ", lowLimitMoney=" + lowLimitMoney + ", benefitMoney=" + benefitMoney
               + ", eachFullMoney=" + eachFullMoney + ", eachFewNumber=" + eachFewNumber
               + ", goodsGiftsGroupId=" + goodsGiftsGroupId + ", priority=" + priority
               + ", isEnable=" + isEnable + ", createdDate=" + createdDate + ", createdName="
               + createdName + ", updatedDate=" + updatedDate + ", updatedName=" + updatedName
               + "]";
    }

}
